package constants

import (
	"os"
	"runtime"
	"strings"
	"time"
)

const (
	ScaleJobAppLabel = "cke-scale-nodes-job"
	DownJobAppLabel  = "cke-down-nodes-job"

	CompletedStatus = "Completed"
	RunningStatus   = "Running"
	FailedStatus    = "Failed"
)

const (
	CkeNodeRoleMaster = "master"
	CkeNodeRoleWorker = "worker"
	NodeMasterLabel   = "node-role.kubernetes.io/master=true"
	NodeWorkerLabel   = "node-role.kubernetes.io/node=true"

	//constants for ckeComponent
	CkeComponentScriptTempRoot = "/script"
	CkeComponentScriptPath     = "/opt/ckeadm-script"
	CkectlScriptPath           = "/opt/ckectl-script"
	CkeComponentLogPath        = "/var/log"
	CkeCompInstalled  = "/opt/cke-comp-installed"
	ForceInstall = "forceInstall"
	SkipDelete = "skipDelete"

	//cluster create status
	CkeStatusInstall   = "Installing"
	CkeStatusFailed    = "Failed"
	CkeStatusCompleted = "Completed"
	CkeStatusExited    = "Exited"
	CkeStatusUnknown   = "Unknown"
	CkeStatusPrepare   = "Preparing"

	CkeDeployConfigPath = "/opt/ckeadm"

	CkeDeployContainerName = "ckeadm-create-container"

	// Ansible log level: 1, 2 OR 3
	AnsibleLogLevel = 2

	AnsiblePlaybookCommand = "ansible-playbook"

	AnsibleLogDir  = "/var/log/ckectl"
	CkeDeployDir   = "/opt/kubernetes-deploy"
	AnsibleInvPath = "my_inventory/my_inventory.cfg"
	AnsibleAllPath = "my_inventory/group_vars/all.yml"

	AnsibleConfig    = CkeDeployDir + "/" + AnsibleInvPath
	AnsibleAllConfig = CkeDeployDir + "/" + AnsibleAllPath

	RootPrivateKey = "/root/.ssh/id_rsa"

	AnsibleTimeOut = "600"

	DockerdPath = "/usr/bin"

	WhichDockerd = DockerdPath + "/dockerd"

	CkectlContainerName = "cke-deploy-runner"

	WhichCkectl = "/usr/local/bin/ckectl"

	WaitCallRetryInterval = 500 * time.Millisecond

	WaitRestartTimeout = 1 * time.Minute

	PullImageInterval = 5 * time.Second

	PullImageTimeout = 5 * time.Minute

	CkectlUpPhaseNum = 27

	ClusterConfigDefault = "cluster.yml"

	SourcesDir = "/etc/kubernetes/crs/"

	SourcesFile = "sources.yml"

	CkeadmWatchServiceName = "ckeadm-wait"

	WhichCkeadm = "/usr/local/bin/ckeadm"

	ClusterIdDefault = "unknow_cluster_id"

	CkeadmWaitInfoPattern = "/info"

	CkeadmWaitProgressPattern = "/progress/"

	CkeadmWaitHealthzPattern = "/healthz"

	CkeadmWaitLogPattern = "/log"

	// ansible done files
	AnsibleUpDoneFile        = "up.done"
	AnsibleScaleDownDoneFile = "scale.down.done"
	AnsibleScaleDoneFile     = "scale.done"
	AnsibleUpdateDoneFile    = "update.done"

	CkeadmLogCacheDir = "/var/log/ckeadm"

	EmptyString = ""
	WaitPort    = 2376

	SourceContainerPath = "/opt/ckectl/sources.yml"

	NginxKubeApiserverPort = 8443

	AnsibleForkNumber = 500

	NodeSkipAnnotations = "ckenode.inspur.com/skipped"

	DefaultKeyFile = "/root/.ssh/id_rsa"

	ClusterDir   = "cluster"
	ScaleUpDir   = "kube-scale"
	ScaleDownDir = "kube-scaledown"

	RegistryDefault = "registry-jinan-lab.inspurcloud.cn"

	PrivateKey = `
LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBMjR0d0R3cjVZ
R2RGcmFmaFFNSHlHenlyRExuU1pMMEc3Sk5ralhKZ25NMFJzVmxNCkh2SkJWWXNheWE4T0ZtRFMx
TDJXYzdnRkJCQ0gvREFsT0pCUjE1aTRUUEF6UUN1QXdramdSTDk3WktrUjlpeXUKNzVWZkRPOWE2
SUx2Vm9jUCtOSVQ2T2kxR1RzYXhLaXJRWFJQVnh5M2xQUG5VaDRQN3hNVmN4NEhaQnZxYTBDdgp5
eCsrT2hSUzRyYzRISWJ0RXBLVDh6NGN1dTBmbXR3UDZkeG95WjJSMEZuK0NmR29XYXlCd1RNRmNq
NnAzenNzCnRBdkRUUGM2ZjFxbmtNbU9vQ2srRHhmdkxrd0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iWE13OENnWUFqYXMwMjJFT2dZdmxyTWJCWEtWc08Kb1hZ
blJudjJHdDNnanlwd3lma1ZPcmRvYkQ3ZEE5T3Z3TkZPYTdwbWdOVWRRZVI5d0daZDd6S2trTXNw
WVdmUgpXRFJyZmJLZ1FJYVpKZ3RFZ3FWeE96YkdnYWErVStOSFdiTkNYYmw0Qm43SnF5VFEwdTFF
VHFVWU00OUFUeVpKCnU3cnU2WTdPdHN3cWV4QzZuSjBDQVFLQmdRQ21aRGV4QmM3YmgxSk9rZHVG
ZmszRCtlNHRTdE0zMWRBU1ZKNFIKNEpPT1JLbHRxZ2tPMlAwU28zeWtRQko1QlMzTklWbkJJQVo0
UmFnTWx3NzB6THZQV3NtSVQ5bG1BTzMrOVZQbwpMM09XTDAvTmRFTGtwWUZUa3dvOTNNQjJKWlYz
VkovUHA3NkVwUXBUMTFQTjY2a2NBRllsTW1jNTZqTVNFWHVMClVqbStDd0tCZ0hRaUpNMXN6aXFq
Y0YyNFUyMUVlVGdlclYwWUY4L3A2UUptK0RXSXNZYUtaTm1jaEhCS3VrR2wKQy9wWklxQ2RMYzVG
Y2tXRlZhSFhhaG9LUzViQVFSdVVONWZmOWk3dHFka1REZ0ZCMndUdStRT3FMVndRTXBRRQphVDFu
TkdCb1d1eE55MW5keE1CVTIwbzJyd3dzNXVWNzBZMWRoS2JNTU9rSW5uelpvckk4Ci0tLS0tRU5E
IFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
`
)

var (
	archs = map[string]string{
		"arm64":    "arm64",
		"amd64":    "amd64",
		"mips64el": "mips64el",
		"mips64le": "mips64el",
	}

	ARCH = archs[runtime.GOARCH]
)

var (
	ScriptImageRepo = "library/cke/components/"

	AnsibleImageRepo = "library/cke/cke-deploy-v4"
	CkeadmOverwrite  = true
	PrivateKeyNoLine = strings.ReplaceAll(PrivateKey, "\n", "")

	Debug = func() bool {
		if "true" == os.Getenv("CkeadmDebug") {
			return true
		}
		return false
	}()
)
